package com.lxitedu;

import org.xml.sax.helpers.*;
import org.xml.sax.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) yaoqi 2006</p>
 *
 * <p>Company: scut_eb</p>
 *
 * @author not attributable
 * @version 1.0
 */
public class WeatherBean extends DefaultHandler {int i=1;String weather[]={"",""};
    public void startElement(String uri, String localName, String qName, Attributes attributes)
throws SAXException {
        String when="";
        if("yweather:forecast".equals(qName)) {if(i==1){when=" 今日 ";}else{when=" 明日 ";}
            String s_date = attributes.getValue(1);
            Date date = null;
            try {
                date = new SimpleDateFormat("dd MMM yyyy", Locale.US).parse(s_date);
            }
            catch (Exception e) {
                e.printStackTrace();
                throw new SAXException("Cannot parse date: " + s_date);
            }
            int low = Integer.parseInt(attributes.getValue(2));
            int high = Integer.parseInt(attributes.getValue(3));
            String text = attributes.getValue(4);
            int code = Integer.parseInt(attributes.getValue(5));
            weather[i-1]=when+weather(text) + ","+wherewind(code)+low + "－" + high+"℃";
            i++;
        }
        super.startElement(uri, localName, qName, attributes);
    }
    public String weather(String eng){
        String chs="";
        if(eng.equals("Clear")){chs="清爽无云";}
        else if(eng.equals("Sunny")){chs="阳光照耀";}
        else if(eng.equals("Partly Cloudy")){chs="局部有云";}
        else if(eng.equals("Mostly Clear")){chs="貌似无云";}
        else if(eng.equals("Mostly Sunny")){chs="点点云朵";}
        else if(eng.equals("Showers")){chs="小雨";}
        else if(eng.equals("Mostly Cloudy")){chs="云彩多多";}
        else if(eng.equals("Mostly Cloudy")){chs="云彩多多";}
        else if(eng.equals("Cloudy")){chs="阴云密布";}
        else if(eng.equals("Sunny/Wind")){chs="晴转多云";}
        else if(eng.equals("AM Clouds/PM Sun/Wind")){chs="多云转晴";}
        else if(eng.equals("AM Showers")){chs="清晨小雨";}
        else{chs=eng;}
        return chs;}
    public String wherewind(int a)
    {
        String wind="error";
        if(a>337 && a<=360){return "北风";}
        else if(a>=0 && a<=22){return "北风";}
        else if(a>22 && a<=67){return "东北风";}
        else if(a>67 && a<=112){return "东风";}
        else if(a>112 && a<=157){return "东南风";}
        else if(a>157 && a<=202){return "南风";}
        else if(a>202 && a<=247){return "西南风";}
        else if(a>247 && a<=292){return "西风";}
        else if(a>292 && a<=337){return "西北风";}
        return wind;
      }
      public String getWeather(int i){
        return weather[i];}
}